package org.moflon.moca;
import java.io.File;
import org.apache.log4j.BasicConfigurator;
import org.moflon.moca.vhdl.parser.VhdlParserAdapter;
import org.moflon.util.eMoflonEMFUtil;
import Moca.CodeAdapter;
import Moca.MocaFactory;
import MocaTree.Folder;
import MocaTree.MocaTreePackage;

public class MocaMain 
{

  private static CodeAdapter codeAdapter;

  public static void main(String[] args) 
  {
    BasicConfigurator.configure();

    // Register parsers and unparsers
    codeAdapter = MocaFactory.eINSTANCE.createCodeAdapter();
    codeAdapter.getParser().add(new VhdlParserAdapter());
//    codeAdapter.getUnparser().add(new VhdlUnparserAdapter());

    // Perform text-to-tree
    Folder tree = codeAdapter.parse(new File("instances/in/"));

    // Save tree to file
    eMoflonEMFUtil.saveModel(MocaTreePackage.eINSTANCE, tree, "instances/tree.xmi");

//    // Perform tree-to-model
//    TreeToVHDL transformer = VHDLCodeAdapterFactory.eINSTANCE.createTreeToVHDL();
//    transformer.transform(tree);
//    
//    // Save model to file
//    for (VHDLSpecification spec : transformer.getVhdlspecification()) {		
//    	eMoflonEMFUtil.saveModel(VHDLCodeAdapterPackage.eINSTANCE, spec, "instances/" + spec.getName() + ".xmi");
//	}
    
    // Perform model-to-tree
    //TODO
    
    // Perform tree-to-text (using initial tree)
    //TODO codeAdapter.unparse("instances/out", tree);    
  }
}